package com.yumis.service.modules.car.controller;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.CarTaskTime;
import com.yumis.service.model.pojo.CategoryParts;
import com.yumis.service.modules.car.service.CategoryPartsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("categoryparts")
public class CategoryPartsController {
    @Autowired
    private CategoryPartsService categoryPartsService;
    /**
     * 新增
     * @param categoryParts
     * @return
     */
    @PostMapping("addCategoryParts")
    public ResponseEntity<Response> addCategoryParts(@Valid CategoryParts categoryParts){
        categoryPartsService.addCategoryParts(categoryParts);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @PostMapping("deleteCategoryPartsById")
    public ResponseEntity<Response> deleteCategoryPartsById(@RequestParam("id") Long id){
        categoryPartsService.deleteCategoryPartsById(id);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
    /**
     * 根据用户id查询
     * @param id
     * @return
     */
    @PostMapping("queryCategoryPartsById")
    public ResponseEntity<Response> queryCategoryPartsById(@RequestParam("id") Long id){
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK,categoryPartsService.queryCategoryPartsById(id)));
    }

    /**
     * 修改
     * @param categoryParts
     * @return
     */
    @PostMapping("updateCategoryParts")
    public ResponseEntity<Response> updateCategoryParts(@Valid CategoryParts categoryParts){
        categoryPartsService.updateCategoryParts(categoryParts);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
}
